home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG Revelations
/
BMUG Revelations.toast
/
Utilities
/
Random
/
Commodore 64c
/
SOURCE
/
Main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-19
|
3KB
|
155 lines
/*
Commodore 64 Emulator v0.2 Earle F. Philhower III
Copyright (C) 1993-4 (st916w9r@dunx1.ocs.drexel.edu)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "ProcessorTypes.h"
#include "Error.h"
#include "Menus.h"
#include "Registers.h"
#include <AppleEvents.h>
#define ALIGNBYTE
#define kAboutDialog 131
Rect dragRect;
EventRecord event;
Cursor commie;
CursHandle commieH;
void Initialize();
main()
{
DialogPtr dialog;
Initialize();
commieH=GetCursor(128);
MoveHHi((Handle)commieH);
HLock((Handle)commieH);
commie=**commieH;
ProcessorLoop();
EventLoop();
}
#define kSplashDialog 129
void Initialize()
{
int err;
DialogPtr dialog;
long temp;
/* Do standard Macintosh initializations */
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(nil);
InitCursor();
/* Set up the menus, drag area */
dragRect=qd.screenBits.bounds;
InsetRect(&dragRect, 2, 2);
if (err=MenuInitialize()) ExitError(err);
/* Display the splash screen, even if for just a second... */
dialog=GetNewDialog(kSplashDialog, nil, (WindowPtr)-1L);
ShowWindow(dialog);
DrawDialog(dialog);
/* Do emulator initializations */
InstructionInitialize();
if (err=MemoryInitialize()) ExitError(err);
if (err=VICInitialize()) ExitError(err);
RegisterInitialize();
TrapInitialize();
SerialInitialize();
PrinterInitialize();
InitializeFloppy();
HardInitialize();
InstallAppleEventHandlers();
/* Done with splash screen, so free its memory */
HideWindow(dialog);
DisposDialog(dialog);
/* Draw the emulator window */
TotalRedrawVIC();
}
EventLoop()
{
int done=0;
char theChar;
while (!done)
{
WaitNextEvent(everyEvent, &event, 0L, nil);
switch(event.what)
{
case nullEvent : break;
case mouseDown : HandleMouseDown(); break;
case autoKey:
case keyDown:
theChar = event.message&charCodeMask;
if ((event.modifiers&cmdKey)!=0)
DoMenuChoice(MenuKey(theChar));
break;
case updateEvt:
BeginUpdate((WindowPtr)event.message);
RedrawVIC();
EndUpdate((WindowPtr)event.message); break;
case kHighLevelEvent :
AEProcessAppleEvent(&event); break;
}
}
}
HandleMouseDown()
{
WindowPtr theWind;
GrafPtr gp;
Point x;
short thePart;
thePart=FindWindow(event.where, &theWind);
switch(thePart) {
case inSysWindow: SystemClick(&event, theWind); break;
case inDrag:
DragWindow(theWind, event.where, &dragRect);
#ifdef ALIGNBYTE
GetPort(&gp);
SetPort(theWind);
x.h=x.v=0;
LocalToGlobal(&x);
x.h&=0xfff8;
MoveWindow(theWind, x.h, x.v, TRUE);
SetPort(gp);
#endif
break;
case inMenuBar: DoMenuChoice(MenuSelect(event.where)); break;
case inContent: ProcessorLoop(); break;
}
}
void CleanUpCommodore()
{
AttachFloppyImage(nil);
}